package sbt.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class AddFilmPage extends AnyPage {

	public AddFilmPage(PageManager pages) {
		super(pages);
	}

  @FindBy(xpath = "//input [@name = 'name']")
  private WebElement TitleField;

  @FindBy(xpath = "//input [@name = 'year']")
  private WebElement YearField;

  @FindBy(name = "submit")
  private WebElement submitButton;
  
  public AddFilmPage setTitleField(String text) {
    TitleField.sendKeys(text);
    return this;
  }
 
  public AddFilmPage setYearField(String text) {
    YearField.sendKeys(text);
    return this;
  }

  public void clickSubmitButton() {
    submitButton.click();
  }

  public AddFilmPage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.id("updateform")));
    return this;
  }
}
